package com.yjt.fresh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.webkit.WebView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiSetMassageHaveChecked;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.constant.MyConstants;
import com.yjt.fresh.utils.PreferenceManager;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 消息详情页
 * Created by mcc on 2018-07-12.
 */

public class AtyMassageDetail extends BaseSimpleActivity {
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.wvAppAtyMassageDetailContent)
    WebView mWebView;
    @BindView(R.id.tvAtyMassageDetailTitle)
    TextView mTvTitle;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_massage_detail;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        String massageContent = getIntent().getStringExtra(MyConstants.MASSAGE_CONTENT);
        String massageTitle = getIntent().getStringExtra(MyConstants.MASSAGE_TITLE);
        mTvTitle.setText(massageTitle);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setDisplayZoomControls(false); //隐藏原生的缩放控件
        mWebView.loadDataWithBaseURL(null, massageContent, "text/html", "utf-8", null);
    }


    @Override
    protected void initEvent() {
        setMassageRead();
        initClick();
    }

    HttpOnNextListener mMassageReadListener = new HttpOnNextListener() {
        @Override
        public void onNext(Object o) {

        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };
    private void setMassageRead(){
        String massageID = getIntent().getStringExtra(MyConstants.MASSAGE_ID);
        ApiSetMassageHaveChecked apiSetMassageHaveChecked = new ApiSetMassageHaveChecked(mMassageReadListener,mContext,false,false,true);
        Map<String,Object> map = new HashMap<>();
        map.put("APPUSERMESSAGE_ID",massageID);
        map.put("SESSION_ID", PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        apiSetMassageHaveChecked.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiSetMassageHaveChecked);
    }
    private void initClick() {
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

}
